﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JsonEditor.Common
{
    public class CPropertyDescriptor : PropertyDescriptor
    {

        CProperty m_Property;



        public CPropertyDescriptor(ref CProperty property, Attribute[] attrs)

            : base(property.Name, attrs)
        {

            m_Property = property;

        }



        #region PropertyDescriptor "region"



        public override bool CanResetValue(object component)
        {

            return false;

        }



        public override Type ComponentType
        {

            get { return null; }

        }



        public override object GetValue(object component)
        {

            return m_Property.Value;

        }



        public override string Description
        {

            get { return m_Property.Name; }

        }



        public override string Category
        {

            get { return m_Property.Category; }

        }



        public override string DisplayName
        {

            get { return m_Property.Name; }

        }



        public override bool IsReadOnly
        {

            get { return m_Property.ReadOnly; }

        }



        public override TypeConverter Converter
        {

            get { return m_Property.Converter; }

        }



        public override void ResetValue(object component)
        {

        }



        public override bool ShouldSerializeValue(object component)
        {

            return false;

        }



        public override void SetValue(object component, object value)
        {

            m_Property.Value = value;

        }



        public override Type PropertyType
        {

            get { return m_Property.Value.GetType(); }

        }



        public override object GetEditor(Type editorBaseType)
        {

            return m_Property.Editor == null ? base.GetEditor(editorBaseType) : m_Property.Editor;

        }

        #endregion

    }

}
